package com.shopping.control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.shopping.dao.impl.BizDaoImpl;
import com.shopping.entity.TbMember;
import com.shopping.service.impl.BizServiceImpl;

/**
 * Servlet implementation class fg_updateServlet
 */
public class fg_updateServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public fg_updateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        // TODO Auto-generated method stub
        response.setCharacterEncoding("gbk");
        response.setContentType("text/html");

        BizDaoImpl bizdao = new BizDaoImpl();
        BizServiceImpl bsi = new BizServiceImpl();
        bsi.setBizdao(bizdao);
        HttpSession session = request.getSession();
        PrintWriter out = response.getWriter();
        if (session.getAttribute("uesr") == null) {
            out.print("<script>");
            out.print("alert('请先登录!');");
            out.print("window.location.href='index.jsp';");
            out.print("</script>");
            out.flush();
            out.close();
            return;
        }

        String name = (String) session.getAttribute("user");

        // System.out.println(name);

        TbMember tbMember = new TbMember();
        tbMember.setName(name);

        TbMember tb = bsi.getonttbmember(tbMember);
        session.setAttribute("TB", tb);
        request.getRequestDispatcher("fg-updateMember.jsp").forward(request, response);

    }

}
